package com.jiaai.web.channel;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.channel.api.InChannelApi;
import com.jiaai.channel.model.InChannelVO;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/admin/channel")
public class ChannelController {
    @Reference
    private InChannelApi inChannelApi;
    /**
     * 添加渠道商
     */
    @PostMapping("/insertChannel")
    public Object insertChannel(@RequestBody InChannelVO inchannelvo){
        try {
            inChannelApi.insertChannel(inchannelvo);
            return RestResultGenerator.genSuccessResult("添加成功");
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("添加失败");
        }

    }
    /**
     * 查询所有渠道商数据
     */
    @GetMapping("/selectAll")
    public Object seachAll(Integer curr,InChannelVO inchannelvo) throws Exception{
        try {
            return RestResultGenerator.genSuccessResult(inChannelApi.selectChannel(curr,inchannelvo));
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("查询失败");
        }
    }
    /**
     * 删除渠道商
     */
    @PostMapping("/deleteChannel/{id}")
    public Object deleChannel(@PathVariable Integer id){
        try {
            inChannelApi.deleteChannel(id);
            return RestResultGenerator.genSuccessResult("删除成功");
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("删除失败");
        }

    }
}
